package com.saas.dao.impl;

import com.saas.dao.IAccountDao;
import com.saas.entity.Account;
import com.saas.util.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class AccountDaoImpl implements IAccountDao {

    private QueryRunner qr = new QueryRunner(DruidUtil.getDataSource());
    @Override
    public boolean login(String username, String password) {

        try {
            String sql = "select * from account where account = ? and password = ?";
            Account a = qr.query(sql, new BeanHandler<Account>(Account.class), new Object[]{username, password});
            return a != null;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
